<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>${name_china}管理列表</title>
<%@include file="/common/head.jsp" %>

</head>
<body class="iframe-page">


<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
        </div>
        <div id="toolbar" style="float: right"></div>
    </div>
    <div class="page-title-border"></div>
</div>

<div id="t-wrap">
    <table class="summer-datagrid" id="dataList">
	    <col width="10%">
	    <col width="10%">
	    <col width="10%">
	    <col width="10%">
	    <col width="10%">
	    <col width="10%">
	    <thead>
		    <tr>
		        <th>排序号1</th>
		        <th>一级分类</th>
		        <th>二级分类</th>
		        <th>属性名称</th>
				<th>创建时间</th>
				<!-- <th>备注</th> -->
		        <th>操作</th>
		    </tr>
	    </thead>
    </table>
</div>

<script>
	//请求url
	var CONST_URL = {
		LIST: basePath + '${common_url}list',
	   	INIT_ADD: basePath + "${common_url}initAdd",
	   	INIT_EDIT: basePath + "${common_url}initEdit",
	   	INIT_VIEW: basePath + "${common_url}initView",
	   	GET_CATEGORY: basePath + "${common_url}getGoodsCategoryCodeid",
	   	DEL: basePath + "${common_url}del"
	};
	
    var  permission = CommonUtil.getPermission('${name_english}');
    
    
    $(function () {
    	
        //新建
        $('#toolbar').on('click', 'a[data-permit="${name_english}:initAdd"]', function() {
        	window.location.href = CONST_URL.INIT_ADD + "?name_id=" + name_id;
		});
        
       createTable();
        
        //查看
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initView"]', function() {
        	var $this = $(this),
        	    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
        	window.location.href = CONST_URL.INIT_VIEW +"?id=" + id;
        });
       
        //编辑
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initEdit"]', function() {
            var $this = $(this),
                id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
            window.location.href = CONST_URL.INIT_EDIT + '?id=' + id;
        });	
        
        //删除
		$('#t-wrap').on('click', 'a[data-permit="${name_english}:del"]', function() {
			var $this = $(this),
			    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
			$.sdialog({
				type: 'confirm',
				msg: '您确定要删除选中的记录吗?',
				onConfirm: function(result) {
				    if (result) {
				    	$.sajax({
			                url : CONST_URL.DEL + "?id=" + id,
			                onLoadSuccess : function() {
			                	 $.stip({
                	                type:'ok',//显示类型 有info、 ok、 danger
                	                text: '删除成功！'    
			                	});
			                	reloadTable();  
			                }
			            });
				    		
				    }	
				}
			});
		});
        
    });
    
    
    // 重新加载表格
	function reloadTable() {
		$('#dataList').datagrid('reload',{
            ajax: {
            	param: {
            		"value": trimSpace($('#value').val()),
                	//"startTime": trimSpace($('#startTime').val()),
                	//"stopTime": trimSpace($('#stopTime').val())
            	}
            }
        });
	}
    
    //创建表格
    function createTable() {
    	$('#dataList').datagrid({
    		ajax: {
    			url: CONST_URL.LIST,
    			param: {
    				"value": trimSpace($('#value').val()),
                	//"startTime": trimSpace($('#startTime').val()),
                	//"stopTime": trimSpace($('#stopTime').val())
            	}
    		},
    		columns: [
    		     {
    		    	 field: 'id',
    		    	 hidden: true
    		     },
    		     {
    		    	 field: 'reorder'
    		     },
    		     {
    		    	 field: 'categoryFirstId'  ,
    		    	 render: function (rowData) {
    		    		 var aa = "";
    		    		 var categoryId = rowData.categoryFirstId
    		    		 
    		    		 $.ajax({
					   			url: CONST_URL.GET_CATEGORY,
					   			type: 'POST',
					   			dataType: 'json',
					   			async:false, 
					   			data:{
					   				"categoryId": categoryId
					   			},
					   			success:function(data){
	    		     				aa = data.name;
					         }
				    	});
    		    		return aa;
       		    	 } 
    		     },
    		     {
    		    	 field: 'categorySecondId' ,
    		    	 render: function (rowData) {
    		    		 var aa = "";
    		    		 var categoryId = rowData.categorySecondId
    		    		 
    		    		 $.ajax({
					   			url: CONST_URL.GET_CATEGORY,
					   			type: 'POST',
					   			dataType: 'json',
					   			async:false, 
					   			data:{
					   				"categoryId": categoryId
					   			},
					   			success:function(data){
	    		     				aa = data.name;
					         }
				    	});
    		    		return aa;
       		    	 } 
    		     },
    		     
    		     {
    		    	 field:'name',
   		    		 render: function (rowData) {
       		    		 return '<a href="javascript:;" data-permit="${name_english}:initView" class="link">'+ rowData.name +'</a>';
       		    	 }
    		     },
    		     {
    		    	 field: 'createTime'
    		     },
    		    {
    		    	 render: function (rowData) {
    		    		 return $.funcbar({
    		    			 data: permission,    //请求的数据
    		    			 type: 'text',     //类型
    		    			 display: 2,    //显示数量
    		    			 permit: ['${name_english}:initEdit', '${name_english}:del'] //需要的权限按钮
    		    		 });
    		    	 }
    		    }
    		          
    	    ]
    	});
    }
</script>
</body>
</html>